<script setup>
import { onMounted, ref } from 'vue'
import axios from 'axios'
import CompoEchartsBar from '@renderer/components/CompoEchartsBar.vue'
import RegistApp from '@renderer/views/RegistApp.vue'
const showUI = ref(true)
const showLinshi = ref(false)
const tDaysLeft = ref(0)
const tishici = ref('')
let gdp_year = ref([])
let gdp_value = ref([])
let chartFontsize = ref(0)
function getdata4chart() {
  let data_ip = '192.168.30.13'
  let data_port = 8080
  axios
    .get(`http://${data_ip}:${data_port}/list`)
    .then((res) => {
      // console.log('成功获取数据：', res)
      res.data.forEach((element) => {
        gdp_year.value.push(element.year)
        gdp_value.value.push(element.gdp_total)
      })
    })
    .catch((err) => {
      console.log(err)
    })
}
function handleBarchartClick(params){
  console.log('父组件收到点击事件：', params)
  window.electron.ipcRenderer.send('bar_chart_click', params.name)
}
function linshiYIncang(){
  showUI.value = true
}
onMounted(() => {
  getdata4chart()
  // handleBarchartClick({
  //   name:' 2014'
  // })
  chartFontsize.value =
    (document.documentElement.clientWidth * 7 + document.documentElement.clientHeight * 12) / 500
  if (document.documentElement.clientWidth / document.documentElement.clientHeight >= 1.7) {
    document.documentElement.style.fontSize =
      (document.documentElement.clientWidth * 9 + document.documentElement.clientHeight * 16) /
        2500 +
      'px'
  } else {
    document.documentElement.style.fontSize =
      (document.documentElement.clientWidth * 7 + document.documentElement.clientHeight * 12) /
        1800 +
      'px'
  }
  window.main2render.send('renderer-ready')
  window.main2render.receive('show-normal', (data) => {
    showUI.value = data.showui
    showLinshi.value = data.showTempBT
    tDaysLeft.value = data.trialDaysLeft
    tishici.value = !data.showTempBT
    ? '软件已超出试用期限，请将新的注册码输入下面的输入框，重新注册软件！'
    : `软件试用期还有${data.trialDaysLeft}天，请尽快联系我们，获得新的注册码`
  })
})
// const ipcHandle = () => window.electron.ipcRenderer.send('ping')
</script>

<template>
  <div id="main_container">
    <CompoEchartsBar
      v-if="showUI"
      id="appcomp"
      chart-type="line"
      :label-fontsize="chartFontsize"
      title-name="中国GDP"
      x-axis-namee="年份"
      :x-axis-data="gdp_year"
      y-axis-name="GDP"
      :y-axis-data="gdp_value"
      @barchart-click="handleBarchartClick"
    ></CompoEchartsBar>
    <RegistApp
      v-if="!showUI"
      id="regcomp"
      :show-temp-b-t="showLinshi"
      :tishixinxi="tishici"
      @ls-hide="linshiYIncang"
    ></RegistApp>
  </div>
</template>

<style lang="scss" scoped>
#main_container {
  width: 100vw;
  height: 100vh;
  #appcomp {
    z-index: 3;
  }
  #regcomp {
    z-index: 2;
  }
}
</style>
